﻿module Supernova {

    export class KissRandom {

        x: number = 123456789;

        y: number = 987654321;

        z: number = 43219876;

        c: number = 6543217;

        public nextUInt32(): number {
            this.x = 314527869 * this.x + 1234567;
            this.y ^= this.y << 5;
            this.y ^= this.y >> 7;
            this.y ^= this.y << 22;
            var t = 4294584393 * this.z + this.c;
            this.c = t >> 32;
            this.z = t;
            return this.x + this.y + this.z;
        }

        public next(): number {
            var a = this.nextUInt32() >> 6;
            var b = this.nextUInt32() >> 5;
            return (a * 134217728.0 + b) / 9007199254740992.0;
        }

    }

}